﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RMS.DataAccess.Entities;
using RMS.DataAccess.Repositories;
using RMS.Utils.MVP;
using RMS.Web.Shell.View;

namespace RMS.Web.Shell.Presenter
{
    public class GetPricePresenter : Presenter<IGetPriceView>
    {
        RadiologyTypeRepository _radiologyTypeRepository;
        ContractsRepository _contractsRepository;

        public GetPricePresenter(RadiologyTypeRepository radiologyTypeRepository, ContractsRepository contractsRepository)
        {
            _radiologyTypeRepository = radiologyTypeRepository;
            _contractsRepository = contractsRepository;
        }

        public IEnumerable<RadiologyType> GetRadiologyTypes()
        {
            return _radiologyTypeRepository.FindAll();
        }
        public IEnumerable<Contracts> getCompanyNams()
        {
            return _contractsRepository.FindAll();
        }
        public decimal getPrice(string radiologyCode, int? contractID)
        {
            decimal price = 0;
            decimal precentage = 0;

            price = (_radiologyTypeRepository.Find(item => item.RadiologyCode = radiologyCode).Single()).Price;

            if (contractID != null)
            {
                precentage = (_contractsRepository.Find(item => item.ContractId = contractID.Value).Single()).Precentage;
                return price - (price / precentage);
            }
            return price;
        }

    }
}
